package com.xmlt.core.template.contentgenerators;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public final class GeneratorRegistry {
	private static Map<String, IContentGeneratorFactory> generatorFactories = new HashMap<String, IContentGeneratorFactory>();

	public static void addGeneratorFactory(String id, IContentGeneratorFactory f) {
		generatorFactories.put(id, f);
	}

	public static Class<?> getGeneratorClass(String id) {
		return generatorFactories.get(id).getTargetClass();
	}

	public static IContentGenerator getGenerator(String id)
			throws InstantiationException, IllegalAccessException {
		IContentGeneratorFactory generatorFactory = generatorFactories.get(id);
		if (generatorFactory == null)
			return null;

		return generatorFactory.getContentGenerator();
	}

	public static List<String> getAllGeneratorIds() {
		List<String> list = new ArrayList<String>();
		list.addAll(generatorFactories.keySet());
		return list;
	}
}
